<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\TryRec;
use services\models\UpFileData;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\TryRecSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '小试推荐';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="try-rec-index">
    <p>
        <?= Html::a('新建小试推荐', ['create'], ['class' => 'btn btn-success']) ?>&nbsp;&nbsp;&nbsp;
        <?= Html::a('刷新缓存', 'javascript:void(0)', ['id'=>'hc']) ?>
    </p>
    
    <div class="box box-success">
        <div class="box-body"><?php echo $this->render('_search', ['model' => $searchModel]); ?></div>
    </div>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'display_position',
            [
            'label'=>'是否显示',
            'value'=> function($data){
                 return TryRec::$STATUS[$data->status];
                }
            ],
            'product1',
            [
            'label'=>'产品名称1',
            'value'=> function($data) use (&$dataArray){
                if(!isset($dataArray[$data->product1]))return '';
                else return $dataArray[$data->product1]['goods_name'];
                }
            ],
            'product2',
            [
            'label'=>'产品名称2',
            'value'=> function($data) use (&$dataArray){
                if(!isset($dataArray[$data->product2]))return '';
                else return $dataArray[$data->product2]['goods_name'];
                }
            ],
            'product3',
            [
            'label'=>'产品名称3',
            'value'=> function($data) use (&$dataArray){
                if(!isset($dataArray[$data->product3]))return '';
                else return $dataArray[$data->product3]['goods_name'];
                }
            ],
            [
            'label'=>'图片',
            'value'=> function($data){
                    $pics = explode(',', $data->pic1);
                    $str = '';
                    if(!empty($pics))
                    {
                        foreach($pics as $v)
                        {
                            $str .=  Html::img(UpFileData::showImage($v),['width'=>'150','height'=>'80']).' &nbsp;&nbsp;&nbsp' ;
                        }
                    }
                    return $str;
                },
                'format'=>'html'
            ],
            
            
             'recommend_time',
            // 'add_user',
            // 'add_time',

            ['class' => 'yii\grid\ActionColumn','template'=>'{update}'],
        ],
    ]); ?>
</div>
